<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>2.2设置请求头</title>
    <style>
      #result{
        width:200px;
        height:100px;
        border:solid 1px #903;
      }
    </style>
</head>
<body>
<div id="result"></div>
<script>
  var result = document.getElementById('result')
  result.onmouseover = function () {
    //1. 创建对象
    var xhr = new XMLHttpRequest()
    //2.初始化
    xhr.open('POST','http://127.0.0.1:8000/serverAll')

    // 设置对应的content-type
    xhr.setRequestHeader('Content-type', 'application/x-www-form-urlencoded')
    xhr.setRequestHeader('name1', 'haha')
    //3.发送
    xhr.send()
    //4.监听状态改变事件
    xhr.onreadystatechange = function () {
      //服务器返回全部信息的时候
      if (xhr.readyState === 4){
        //改变页面内容
        result.innerHTML = xhr.response
      }
    }
  }
</script>
</body>
</html>